package com.tianzeculture.stagebao.activity.artist.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.bean.ImageBean;
import com.tianzeculture.stagebao.bean.MyOfferBean;
import com.tianzeculture.stagebao.bean.PersonnelPoolBean;
import com.tianzeculture.stagebao.view.MyRecyclerview;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.ArrayList;
import java.util.List;

import static com.tianzeculture.stagebao.net.base.AppBaseRestUsageV2.PICTURE_URL;

/**
 * Created by Administrator on 2018/6/9 0009.
 */

public class DataAdapter extends RecyclerView.Adapter<DataAdapter.RecyclerViewHolder> {
    Context context;
    List<PersonnelPoolBean> list;
    List<ImageBean> imageList;
    List<MyOfferBean> offerList;
    List<PersonnelPoolBean> dataList;

    public DataAdapter(Context context, List<PersonnelPoolBean> list, List<ImageBean> imageList, List<MyOfferBean> offerList, List<PersonnelPoolBean> dataList) {
        this.context = context;
        this.list = list;
        this.imageList = imageList;
        this.offerList = offerList;
        this.dataList = dataList;
    }

    @Override
    public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_artist_data, parent, false);
        return new RecyclerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerViewHolder holder, int position) {
        holder.setData(position);
    }

    @Override
    public int getItemCount() {
        return 1;
    }


    class RecyclerViewHolder extends RecyclerView.ViewHolder {
        //        LinearLayout layoutWorks;
        TextView tvHeight;
        TextView tvWeight;
        //        TextView tvBust;
//        TextView tvWaist;
//        TextView tvHipline;
        TextView tvShoeSize;
        TagFlowLayout tagFlowLayout;
        TextView tvExperience;
        MyRecyclerview myRecyclerview;

        public RecyclerViewHolder(View itemView) {
            super(itemView);
//            layoutWorks = itemView.findViewById(R.id.layoutWorks);
            tvHeight = itemView.findViewById(R.id.tvHeight);
//            tvBust = itemView.findViewById(R.id.tvBust);
            tvWeight = itemView.findViewById(R.id.tvWeight);
//            tvWaist = itemView.findViewById(R.id.tvWaist);
//            tvHipline = itemView.findViewById(R.id.tvHipline);
            tvShoeSize = itemView.findViewById(R.id.tvShoeSize);
//            tvStyleTag = itemView.findViewById(R.id.tvStyleTag);
//            tvAppearanceTag = itemView.findViewById(R.id.tvAppearanceTag);
//            tvShapeTag = itemView.findViewById(R.id.tvShapeTag);
//            tvCharmTag = itemView.findViewById(R.id.tvCharmTag);
            tagFlowLayout = itemView.findViewById(R.id.tagFlowLayout);
            tvExperience = itemView.findViewById(R.id.tvExperience);
            myRecyclerview = itemView.findViewById(R.id.myRecyclerview);
        }

        public void setData(int position) {
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
            linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            myRecyclerview.setLayoutManager(linearLayoutManager);
            List<String> stringList = new ArrayList<>();
            for (MyOfferBean offerBean : offerList) {
                stringList.add(offerBean.getParentName() + "-" + offerBean.getName() + "---" + offerBean.getPrice() + "/" + (offerBean.getUnit() == null ? "小时" : offerBean.getUnit()));
            }
            AddPriceAdapter adapter = new AddPriceAdapter(R.layout.item_add_price, stringList);
            myRecyclerview.setAdapter(adapter);

            if (list.size() == 0)
                return;
            PersonnelPoolBean personnelPoolBean = list.get(position);

//            for (int i = 0; i < imageList.size(); i++) {
//                View view = LayoutInflater.from(context).inflate(R.layout.item_artist_data_photo, null);
//                ImageView imageView = view.findViewById(R.id.ivPhoto);
//                Picasso.with(context).load(PICTURE_URL + imageList.get(i).getPath()).into(imageView);
//                layoutWorks.addView(view);
//            }
            tvHeight.setText("身高:" + personnelPoolBean.getUserHeight() + "cm");
//            tvBust.setText("胸围:" + personnelPoolBean.getUserBust() + "cm");
            tvWeight.setText("体重:" + personnelPoolBean.getUserWeight() + "kg");
//            tvWaist.setText("腰围:" + personnelPoolBean.getUserWaist() + "cm");
//            tvHipline.setText("臀围:" + personnelPoolBean.getUserHipline() + "cm");
            tvShoeSize.setText("年龄:" + personnelPoolBean.getShoeSize() + "岁");
//            tvStyleTag.setText(personnelPoolBean.getTag1());
//            tvAppearanceTag.setText(personnelPoolBean.getTag2());
//            tvShapeTag.setText(personnelPoolBean.getTag3());
//            tvCharmTag.setText(personnelPoolBean.getTag4());

            List<String> strings = new ArrayList<>();
            String tag1 = dataList.get(0).getTag1();
            strings.addAll(getTags(tag1));
            String tag2 = dataList.get(0).getTag2();
            strings.addAll(getTags(tag2));
            String tag3 = dataList.get(0).getTag3();
            strings.addAll(getTags(tag3));
            tagFlowLayout.setAdapter(new TagAdapter<String>(strings) {
                @Override
                public View getView(FlowLayout parent, int position, String o) {
                    View view = LayoutInflater.from(context).inflate(R.layout.item_characteristic,
                            tagFlowLayout, false);
                    TextView tvCharacteristic = view.findViewById(R.id.tvCharacteristic);
                    tvCharacteristic.setText(o);
                    if (position % 4 == 0)
                        tvCharacteristic.setBackgroundResource(R.drawable.bg_lightpink_round);
                    else if (position % 4 == 1)
                        tvCharacteristic.setBackgroundResource(R.drawable.bg_lightpurple_round);
                    else if (position % 4 == 2)
                        tvCharacteristic.setBackgroundResource(R.drawable.bg_lightorange_round);
                    else if (position % 4 == 3)
                        tvCharacteristic.setBackgroundResource(R.drawable.bg_lightgreen_round);
                    return view;
                }
            });
            tvExperience.setText(personnelPoolBean.getExperience());
        }
    }

    private List<String> getTags(String tag) {
        List<String> list = new ArrayList<>();
        if (tag == null)
            return list;
        if (!"".equals(tag)) {
            if (tag.contains(",")) {
                String[] arr = tag.split(",");
                for (String str : arr) {
                    list.add(str);
                }
            } else {
                list.add(tag);
            }
        }
        return list;
    }
}